<!-- 模板 -->
<template>
  <div class="root">
    <div
      class="content"
      v-for="(item, index) in content"
      :key="index"
      @click="getActive(index)"
      :class="index === activeIndex ? 'active' : ''"
    >
      <div class="num">{{ index + 1 > 10 ? index + 1 : '0' + (index + 1) }}</div>
      <div class="des">
        <div>{{ item.title }}</div>
        <div class="time">{{ item.shijian }}</div>
      </div>
      <div v-if="index === activeIndex" class="state">
        <i class="iconfont icon-nowplay"></i>
      </div>
      <div v-else class="state">{{ item.h3 }}</div>
    </div>
  </div>
</template>
<script>
import request from '../utils/request.js'
export default {
  name: '',
  data() {
    return {
      palyValue: this.$route.query.playValue,
      activeIndex: 0,
      content: [],
    }
  },
  props: [],
  components: {},
  computed: {},
  filters: {},
  methods: {
    //获取点击目录的那一条
    getActive(index) {
      this.palyValue = 0
      this.activeIndex = index
      this.outPut()
    },
    //请求目录列表
    async getUser() {
      let options = {
        url: '/content',
        type: 'get',
        data: { id: 1 },
      }
      try {
        let { data: res } = await request(options)
        if (res.meta.status !== 200) {
          console.log(res.meta.msg)
        }
        this.content = res.data
      } catch (err) {
        console.log(err)
      }
    },
    //向父组件传值,使每次点击目录中的音频时进度条和按钮刷新
    outPut() {
      this.$emit('index2', 1, { value: 0, auto: 'play' })
    },
  },
  created() {},
  mounted() {
    this.getUser(), this.outPut()
  },
}
</script>
<style lang="less" scoped>
// @import url(); 引入公共css类
.root {
  padding: 0 0.2rem;
  overflow: auto;
  height: calc(100vh - 8rem);
}

.content {
  width: 100%;
  font-size: 0.28rem;
  display: flex;
  justify-content: space-between;
  padding: 0.05rem 0;
  border-bottom: 1px solid #f5f5f5;
  .num {
    width: 10%;
    font-size: 0.24rem;
    color: #666;
  }
  .des {
    width: 65%;
    .time {
      color: #666;
      font-size: 0.24rem;
    }
  }
  .state {
    width: 25%;
    text-align: right;
    align-self: center;
  }
}
.active {
  .des {
    color: #fc1e1e;
    .time {
      color: #fc1e1e;
    }
  }
  .state {
    color: #fc1e1e;
  }
}
</style>
